<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
        <link rel="stylesheet" type="text/css" href="assets/lib/layui/css/layui.css" />
        <link rel="stylesheet" type="text/css" href="assets/css/common.css" />


    </head>
    <body>

        <table class="layui-hide" id="test" lay-filter='demo'></table>

        <script type="text/html" id="barDemo">

            <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
        </script>
        <script type="text/javascript" src="assets/lib/layui/layui.js">

        </script>
        <script src="assets/js/baseUrl.js"></script>


        <script>
            layui.use(['jquery', 'table', 'layer'], function() {
                var table = layui.table;
                var $ = layui.jquery;
                var layer = layui.layer;
                $.ajax({
                    method: 'GET',
                    url: '/my/article/list',
                    data: {
                        pagenum: 10,
                        pagesize: 1000
                    },
                    success: function(result) {
                        if (result.status == 0) {
                            console.log(result);
                            table.render({
                                elem: '#test',
                                data: result.data,
                                limit: 1,
                                limits: [1, 3, 5, 10],
                                cols: [
                                    [{
                                            field: 'Id',
                                            title: '编号',
                                            sort: true
                                        }, {
                                            field: 'title',
                                            title: '标题'
                                        }, {
                                            field: 'pub_date',
                                            title: '发布日期',
                                            sort: true
                                        }, {
                                            field: 'state',

                                            title: '状态'
                                        }, {
                                            field: 'cate_name',
                                            title: '文章类别',
                                        },
                                        {
                                            field: '',
                                            title: '操作',
                                            toolbar: '#barDemo'
                                        }
                                    ]
                                ],
                                page: true
                            });


                        }
                    }
                })

                //监听工具条
                table.on('tool(demo)', function(obj) {

                    var data = obj.data;

                    if (obj.event == 'del') {
                        layer.confirm('确认删除？', function(index) {
                            $.get('/my/article/delete/' + data.Id, function(result) {
                                parent.document.location.reload();
                            });
                            layer.close(index);
                        })

                    }
                });

            });
        </script>
    </body>
</html>
